﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using NS.Utilities;
using NS.BLL.Systems;
using BLL;
using Model;

public partial class Platform_PartnerManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            txtPartnerNo.Text = PartnerService.CreatePartnerNo();
            GridViewDataBind();
        }
    }

    private void GridViewDataBind()
    {
        FGridView1.SQLString = PartnerService.GetAllPartner_SQL();
        FGridView1.PKey = "ID";
        FGridView1.OrderName = "ID";
        FGridView1.BindData();
        FGridView1.AddControl();
    }
    protected void btnBindData_Click(object sender, EventArgs e)
    {
        GridViewDataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Partner Model = new Partner();
        Model.PartnerNo = "S" + txtPartnerNo.Text.Trim().ToUpper();
        Model.PartnerName = txtPartnerName.Text.Trim();
        Model.Address = txtAddress.Text.Trim();
        Model.LianXR = txtLianXR.Text.Trim();
        Model.LianXDH = txtLianXDH.Text.Trim();
        Model.Num = int.Parse(txtNum.Text.Trim());

        if (PartnerService.AddPartner(Model) > 0)
        {
            txtPartnerNo.Text = PartnerService.CreatePartnerNo();
            txtPartnerName.Text = string.Empty;
            txtAddress.Text = string.Empty;
            txtLianXR.Text = string.Empty;
            txtLianXDH.Text = string.Empty;
            GridViewDataBind();
        }
        else
        {
            MessageBox.ShowSaveError(this);
        }
    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        string ID = ((Button)sender).CommandArgument.ToString();
        PartnerService.DeletePartnerById(Convert.ToInt32(ID));
        GridViewDataBind();
    }
}